package com.admission.web;

import java.io.File;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.admission.model.TeacherView;
import com.admission.service.TeacherViewManager;
import com.admission.util.PageUtils;
@Namespace("/base")
@Results({@Result(name = CrudActionSupport.RELOAD, location = "/base/index.action", type = "redirect") })
public class TeacherViewAction extends CrudActionSupport<TeacherView>{

	private static final long serialVersionUID = 488185923443490311L;
	private String id;
	private TeacherView entity;
	private File picture;
	private String pictureFileName;
	private Page<TeacherView> page = new Page<TeacherView>(PageUtils.MAIN_ENROLL);
    private TeacherViewManager teacherViewManager;

	public TeacherView getModel() {
		return entity;
	}

	@Override
	public String list() throws Exception {
		teacherViewManager.getByordTime(page);
		return "list";
	}

	/**
	 * 通过id获取
	 * @param id
	 * @return TeacherView
	 */
	@Override
	public String input() throws Exception {
		entity=teacherViewManager.getTeacherViewById(id); 
		return "detail";
	}

	@Override
	public String save() throws Exception {
		return RELOAD;
	}

	@Override
	public String delete() throws Exception {
		return RELOAD;
	}


	@Override
	protected void prepareModel() throws Exception {
		if(StringUtils.isEmpty(id)){
			entity = new TeacherView();
		}else{
			entity = teacherViewManager.getTeacherViewById(id);
		}
		
	}
   
	/**
	 * 判断名师介绍功能开关状态
	 * @return
	 * @throws Exception
	 */
	public String checkConsult() throws Exception{
			if(teacherViewManager.checkConsult().equals("1"))
				return list();
			else
				//Struts2Utils.renderText("false");
			return "sysfail";
	}
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public TeacherView getEntity() {
		return entity;
	}

	public void setEntity(TeacherView entity) {
		this.entity = entity;
	}

	public Page<TeacherView> getPage() {
		return page;
	}

	public void setPage(Page<TeacherView> page) {
		this.page = page;
	}

	public TeacherViewManager getTeacherViewManager() {
		return teacherViewManager;
	}
    @Autowired
	public void setTeacherViewManager(TeacherViewManager teacherViewManager) {
		this.teacherViewManager = teacherViewManager;
	}

	public File getPicture() {
		return picture;
	}

	public void setPicture(File picture) {
		this.picture = picture;
	}

	public String getPictureFileName() {
		return pictureFileName;
	}

	public void setPictureFileName(String pictureFileName) {
		this.pictureFileName = pictureFileName;
	}

   

}
